package com.hcinfos.gsoo.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hcinfos.gsoo.R;

public class TypeSingleSelectAdapter extends BaseAdapter {

	private Context context;
	private List<String> list;
	private LayoutInflater mInflater;
	public int index = 0;

	public TypeSingleSelectAdapter(Context context, List<String> list) {
		this.context = context;
		this.list = list;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TypeHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.tc_condition_listview_item, null);
			holder = new TypeHolder();
			holder.nameTv = (TextView) convertView.findViewById(R.id.textview);
			holder.image_line = (ImageView) convertView
					.findViewById(R.id.image_line);
			convertView.setTag(holder);
		} else {
			holder = (TypeHolder) convertView.getTag();
		}
		if (index != -1 && index == position) {
			holder.image_line.setVisibility(View.VISIBLE);
		} else {
			holder.image_line.setVisibility(View.GONE);
		}
		holder.nameTv.setText(list.get(position));
		return convertView;
	}

	private final class TypeHolder {
		TextView nameTv;
		ImageView image_line;
	}

	public void setDataChange(List<String> list) {
		this.list = list;
		notifyDataSetChanged();
	}

	public void setPosition(int index) {
		this.index = index;
	}

}
